package org.arain.baseii.login;

import java.util.List;

import javax.annotation.Resource;

import org.arain.baseii.mapper.SysUserMapper;
import org.arain.baseii.pojo.SysUser;
import org.arain.baseii.pojo.SysUserExample;
import org.arain.baseii.utils.ArainResult;
import org.springframework.stereotype.Service;
@Service
public class LoginServiceImpl implements LoginService{
	@Resource
	private SysUserMapper sysUserMapper;

	@Override
	public ArainResult load_login(LoginDto loginDto) {
		SysUserExample example = new SysUserExample();
		example.createCriteria().andUsernameEqualTo(loginDto.getUsername()).andEnabledEqualTo((short) 1);
		List<SysUser> list = sysUserMapper.selectByExample(example);
		if(list!=null && list.size()>0) {
			for (SysUser sysUser : list) {
				if(sysUser.getPassword().equals(loginDto.getPassword())) {
					return ArainResult.ok(sysUser);
				} else {
					return ArainResult.build(203, "密码错误！");
				}
			}
		}
		return ArainResult.build(201, "用户名错误！");
	}
}
